/*
 * Created on 2005-1-24
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.nauu.atombuilder.modle;

import java.util.List;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.PropertyDescriptor;
import org.eclipse.ui.views.properties.TextPropertyDescriptor;


/**
 * @author nauu
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
@SuppressWarnings("unchecked")
public class Grid extends Node implements IPropertySource {

	private static final long serialVersionUID = 1L;

	final public static String PROP_LOCATION = "LOCATION";

    final public static String PROP_ID = "ID";

    final public static String PROP_NAME = "NAME";

    final public static String PROP_CHECKBOX = "CHECKBOX";
    
    final public static String PROP_USE_PAGE = "USE_PAGE";

    final public static String PROP_PATH = "PROP_PATH";

    final public static String PROP_GRID_ACTS1 = "GRID_ACTS1";

    final public static String PROP_GRID_ACTS2 = "GRID_ACTS2";
    
    final public static String PROP_GRID_ACTS3 = "GRID_ACTS3";
    
    final public static String PROP_GRID_ACTS4 = "GRID_ACTS4";
    
    final public static String PROP_GRID_ACTS5 = "GRID_ACTS5";

    final public static String PROP_GRID_ACTS6 = "GRID_ACTS6";
    
    final public static String PROP_GRID_ACTS7 = "GRID_ACTS7";

    final public static String PROP_GRID_ACTS8 = "GRID_ACTS8";

    
    final public static String PROP_COLUMN1 = "COLUMN1";

    final public static String PROP_COLUMN2 = "COLUMN2";
    
    final public static String PROP_COLUMN3 = "COLUMN3";
    
    final public static String PROP_COLUMN4 = "COLUMN4";
    
    final public static String PROP_COLUMN5 = "COLUMN5";
    
    final public static String PROP_COLUMN6 = "COLUMN6";
    
    final public static String PROP_COLUMN7 = "COLUMN7";
    
    final public static String PROP_COLUMN8 = "COLUMN8";
    
    final public static String PROP_COLUMN9 = "COLUMN9";
    
    final public static String PROP_INPUTS = "INPUTS";

    final public static String PROP_OUTPUTS = "OUTPUTS";

    protected Point location = new Point(0, 0);

//    protected String id = ""+new Date().getTime();
    protected String id = "";

    protected String path;

    protected String name = "Grid";

    protected Boolean checkbox = true;

    protected Boolean usePage = true;

    protected String colName1 = "";
    protected String colName2 = "";
    protected String colName3 = "";
    protected String colName4 = "";
    protected String colName5 = "";
    protected String colName6 = "";
    protected String colName7 = "";
    protected String colName8 = "";
    protected String colName9 = "";

    protected String colMapping1 = "";
    protected String colMapping2 = "";
    protected String colMapping3 = "";
    protected String colMapping4 = "";
    protected String colMapping5 = "";
    protected String colMapping6 = "";
    protected String colMapping7 = "";
    protected String colMapping8 = "";
    protected String colMapping9 = "";
    
    protected static IPropertyDescriptor[] descriptors;

    public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public Boolean getCheckbox() {
		return checkbox;
	}

	public void setCheckbox(Boolean checkbox) {
		this.checkbox = checkbox;
	}

	public Boolean getUsePage() {
		return usePage;
	}

	public void setUsePage(Boolean usePage) {
		this.usePage = usePage;
	}

	public String getColName1() {
		return colName1;
	}

	public void setColName1(String colName1) {
		this.colName1 = colName1;
	}

	public String getColName2() {
		return colName2;
	}

	public void setColName2(String colName2) {
		this.colName2 = colName2;
	}

	public String getColName3() {
		return colName3;
	}

	public void setColName3(String colName3) {
		this.colName3 = colName3;
	}

	public String getColName4() {
		return colName4;
	}

	public void setColName4(String colName4) {
		this.colName4 = colName4;
	}

	public String getColName5() {
		return colName5;
	}

	public void setColName5(String colName5) {
		this.colName5 = colName5;
	}

	public String getColName6() {
		return colName6;
	}

	public void setColName6(String colName6) {
		this.colName6 = colName6;
	}

	public String getColName7() {
		return colName7;
	}

	public void setColName7(String colName7) {
		this.colName7 = colName7;
	}

	public String getColName8() {
		return colName8;
	}

	public void setColName8(String colName8) {
		this.colName8 = colName8;
	}

	public String getColName9() {
		return colName9;
	}

	public void setColName9(String colName9) {
		this.colName9 = colName9;
	}

	public String getColMapping1() {
		return colMapping1;
	}

	public void setColMapping1(String colMapping1) {
		this.colMapping1 = colMapping1;
	}

	public String getColMapping2() {
		return colMapping2;
	}

	public void setColMapping2(String colMapping2) {
		this.colMapping2 = colMapping2;
	}

	public String getColMapping3() {
		return colMapping3;
	}

	public void setColMapping3(String colMapping3) {
		this.colMapping3 = colMapping3;
	}

	public String getColMapping4() {
		return colMapping4;
	}

	public void setColMapping4(String colMapping4) {
		this.colMapping4 = colMapping4;
	}

	public String getColMapping5() {
		return colMapping5;
	}

	public void setColMapping5(String colMapping5) {
		this.colMapping5 = colMapping5;
	}

	public String getColMapping6() {
		return colMapping6;
	}

	public void setColMapping6(String colMapping6) {
		this.colMapping6 = colMapping6;
	}

	public String getColMapping7() {
		return colMapping7;
	}

	public void setColMapping7(String colMapping7) {
		this.colMapping7 = colMapping7;
	}

	public String getColMapping8() {
		return colMapping8;
	}

	public void setColMapping8(String colMapping8) {
		this.colMapping8 = colMapping8;
	}

	public String getColMapping9() {
		return colMapping9;
	}

	public void setColMapping9(String colMapping9) {
		this.colMapping9 = colMapping9;
	}

	public List getOutputs() {
		return outputs;
	}

	public void setOutputs(List outputs) {
		this.outputs = outputs;
	}

	public List getInputs() {
		return inputs;
	}

	public void setInputs(List inputs) {
		this.inputs = inputs;
	}

	public String getName() {
        return name;
    }

    public void setName(String name) {
        if (this.name.equals(name)) {
            return;
        }
        this.name = name;
        firePropertyChange(PROP_NAME, null, name);
    }

    public void setLocation(Point p) {
        if (this.location.equals(p)) {
            return;
        }
        this.location = p;
        firePropertyChange(PROP_LOCATION, null, p);
    }

    public Point getLocation() {
        return location;
    }

    //------------------------------------------------------------------------
    // Abstract methods from IPropertySource

    public Object getEditableValue() {
        return this;
    }

    public IPropertyDescriptor[] getPropertyDescriptors() {
        if (descriptors == null) {
            // Create a descriptor and set a category
        	ComboBoxPropertyDescriptor visible =  new ComboBoxPropertyDescriptor(PROP_VISIBLE, "visible", new String[] { "true", "false" });
        	visible.setCategory("基本属性");
        	
        	PropertyDescriptor id = new PropertyDescriptor(PROP_ID, "id");
        	id.setCategory("基本属性");
        	
        	TextPropertyDescriptor name = new TextPropertyDescriptor(PROP_NAME, "name");
        	name.setCategory("基本属性");

        	ComboBoxPropertyDescriptor mode = new ComboBoxPropertyDescriptor(PROP_MODE, "mode", new String[] { "loop", "pop" });
        	mode.setCategory("基本属性");
        	
        	TextPropertyDescriptor classpath = new TextPropertyDescriptor(PROP_PATH, "path");
        	classpath.setCategory("基本属性");
        	
        	ComboBoxPropertyDescriptor checkbox = new ComboBoxPropertyDescriptor(PROP_CHECKBOX, "checkbox", new String[] { "true", "false" });
        	checkbox.setCategory("基本属性");
        	
        	ComboBoxPropertyDescriptor usePage = new ComboBoxPropertyDescriptor(PROP_USE_PAGE, "usePage", new String[] { "true", "false" });
        	usePage.setCategory("基本属性");
        	
        	TextPropertyDescriptor col1 = new TextPropertyDescriptor(PROP_COLUMN1, "header");
        	TextPropertyDescriptor colMapping1 = new TextPropertyDescriptor("MAPPING1", "mapping");
        	col1.setCategory("第一列");
        	colMapping1.setCategory("第一列");

        	
        	TextPropertyDescriptor col2 = new TextPropertyDescriptor(PROP_COLUMN2, "header");
        	TextPropertyDescriptor colMapping2 = new TextPropertyDescriptor("MAPPING2", "mapping");
        	col2.setCategory("第二列");
        	colMapping2.setCategory("第二列");
        	
        	
        	TextPropertyDescriptor col3 = new TextPropertyDescriptor(PROP_COLUMN3, "header");
        	TextPropertyDescriptor colMapping3 = new TextPropertyDescriptor("MAPPING3", "mapping");
        	col3.setCategory("第三列");
        	colMapping3.setCategory("第三列");
        	
        	TextPropertyDescriptor col4 = new TextPropertyDescriptor(PROP_COLUMN4, "header");
        	TextPropertyDescriptor colMapping4 = new TextPropertyDescriptor("MAPPING4", "mapping");
        	col4.setCategory("第四列");
        	colMapping4.setCategory("第四列");
        	
        	TextPropertyDescriptor col5 = new TextPropertyDescriptor(PROP_COLUMN5, "header");
        	TextPropertyDescriptor colMapping5 = new TextPropertyDescriptor("MAPPING5", "mapping");
        	col5.setCategory("第五列");
        	colMapping5.setCategory("第五列");
        	
        	TextPropertyDescriptor col6 = new TextPropertyDescriptor(PROP_COLUMN6, "header");
        	TextPropertyDescriptor colMapping6 = new TextPropertyDescriptor("MAPPING6", "mapping");
        	col6.setCategory("第六列");
        	colMapping6.setCategory("第六列");
        	
        	TextPropertyDescriptor col7 = new TextPropertyDescriptor(PROP_COLUMN7, "header");
        	TextPropertyDescriptor colMapping7 = new TextPropertyDescriptor("MAPPING7", "mapping");
        	col7.setCategory("第七列");
        	colMapping7.setCategory("第七列");
        	
        	TextPropertyDescriptor col8 = new TextPropertyDescriptor(PROP_COLUMN8, "header");
        	TextPropertyDescriptor colMapping8 = new TextPropertyDescriptor("MAPPING8", "mapping");
        	col8.setCategory("第八列");
        	colMapping8.setCategory("第八列");
        	
            descriptors = new IPropertyDescriptor[]{
        		visible,
            	mode,
            	id,
        		name,
        		classpath,
            	checkbox,
            	usePage,
            	col1,
            	col2,
            	col3,   
            	col4,   
            	col5,   
            	col6,   
            	col7,   
            	col8,   
            	colMapping1,        
            	colMapping2,        
            	colMapping3,      
            	colMapping4,        
            	colMapping5,        
            	colMapping6,        
            	colMapping7,        
            	colMapping8        
            };
        }else{
        	if(descriptors.length == 0)
        		descriptors = new IPropertyDescriptor[]{};
        }
        return descriptors;
    }

    public Object getPropertyValue(Object id) {
    	if (PROP_VISIBLE.equals(id))
            return isVisible() ? new Integer(0) : new Integer(1);
        if (PROP_ID.equals(id))
            return getId();
        if (PROP_MODE.equals(id))
        	return getMode() ? new Integer(0) : new Integer(1);
        if (PROP_NAME.equals(id))
        	return getName();
        if (PROP_PATH.equals(id))
        	return getPath();
        if (PROP_CHECKBOX.equals(id))
        	return getCheckbox() ? new Integer(0) : new Integer(1);
        if (PROP_USE_PAGE.equals(id))
        	return getUsePage() ? new Integer(0) : new Integer(1);
        if (PROP_COLUMN1.equals(id))
        	return getColName1();
        if (PROP_COLUMN2.equals(id))
        	return getColName2();
        if (PROP_COLUMN3.equals(id))
        	return getColName3();
        if ("MAPPING1".equals(id))
        	return getColMapping1();
        if ("MAPPING2".equals(id))
        	return getColMapping2();
        if ("MAPPING3".equals(id))
        	return getColMapping3();
        return null;
    }

    public boolean isPropertySet(Object id) {
        return true;
    }

    public void resetPropertyValue(Object id) {

    }

    public void setPropertyValue(Object id, Object value) {
    	if (PROP_VISIBLE.equals(id))
            setVisible(((Integer) value).intValue() == 0);
        if (PROP_ID.equals(id))
            setId((String)value);
        if (PROP_MODE.equals(id))
        	setMode(((Integer) value).intValue() == 0);
        if (PROP_NAME.equals(id))
        	setName((String)value);
        if (PROP_PATH.equals(id))
        	setPath((String)value);
        if (PROP_USE_PAGE.equals(id))
        	setUsePage(((Integer) value).intValue() == 0);
        if (PROP_CHECKBOX.equals(id))
        	setCheckbox(((Integer) value).intValue() == 0);
        if (PROP_COLUMN1.equals(id))
        	setColName1((String)value);
        if (PROP_COLUMN2.equals(id))
        	setColName2((String)value);
        if (PROP_COLUMN3.equals(id))
        	setColName3((String)value);
        if ("MAPPING1".equals(id))
        	setColMapping1((String)value);
        if ("MAPPING2".equals(id))
        	setColMapping2((String)value);
        if ("MAPPING3".equals(id))
        	setColMapping3((String)value);
    }
    
    
}